﻿using Microsoft.AspNetCore.SignalR;
using PLCS.Application.EquipmentApp.Hubs;
using PLCS.Application.StationApp.Hubs;
using PLCS.Domain.Shared.Stations;

namespace PLCS.Web.EventHandlers.Stations;

public class StationHaveStatusChangeHandler : ILocalEventHandler<StationHaveStatusChangeEvent>, ITransientDependency
{
    private readonly IHubContext<FrameHub> _hubcontext;

    public StationHaveStatusChangeHandler(IHubContext<FrameHub> hubcontext)
    {
        _hubcontext = hubcontext;
    }

    public async Task HandleEventAsync(StationHaveStatusChangeEvent eventData)
    {
        await _hubcontext.Clients.All.SendAsync("ChangeStationStatus", eventData.StaNum, eventData.HaveStatus);
    }
}